package com.xiaochong.tir.trades.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Created by org on 2018/6/15.
 * Bitfinex队列绑定
 */
@Configuration
@Component
public class BitfinexQueenConfig {
    /**
     * 配置消息交换机
     * 针对消费者配置
     FanoutExchange: 将消息分发到所有的绑定队列，无routingkey的概念
     HeadersExchange ：通过添加属性key-value匹配
     DirectExchange:按照routingkey分发到指定队列
     TopicExchange:多关键字匹配
     */
    @Bean
    public DirectExchange BitfinexNodeAPIExchange() {
        return new DirectExchange(ExchangeQueue.Exchange.EX_NODE_API_MQ, true, false);
    }
    @Bean
    public Queue queueTradesBitfinexBtcAction(){
        return new Queue(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_BTC, true);
    }
    @Bean
    public Binding bindingTradesBitfinexBtcAction(){
        return BindingBuilder.bind(queueTradesBitfinexBtcAction()).to(BitfinexNodeAPIExchange()).with(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_BTC);
    }

    @Bean
    public Queue queueTradesBitfinexUsdtAction(){
        return new Queue(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_USDT, true);
    }
    @Bean
    public Binding bindingTradesBitfinexUsdtAction(){
        return BindingBuilder.bind(queueTradesBitfinexUsdtAction()).to(BitfinexNodeAPIExchange()).with(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_USDT);
    }

    @Bean
    public Queue queueTradesBitfinexEthAction(){
        return new Queue(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_ETH, true);
    }
    @Bean
    public Binding bindingTradesBitfinexEthAction(){
        return BindingBuilder.bind(queueTradesBitfinexEthAction()).to(BitfinexNodeAPIExchange()).with(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_ETH);
    }
    @Bean
    public Queue queueTradesBitfinexUsdAction(){
        return new Queue(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_USD, true);
    }
    @Bean
    public Binding bindingTradesBitfinexUsdAction(){
        return BindingBuilder.bind(queueTradesBitfinexUsdAction()).to(BitfinexNodeAPIExchange()).with(BitfinexMqQueue.QUEUE_TRADES_BITFINEX_USD);
    }
}
